package hellfire.system.graphics;

/**
 * Represents coordinates in range ([-asp, +asp],[-1, +1])
 *
 */
public class GLVec2 
{
	private float x,y;
	
	public GLVec2(double x, double y)
	{
		this.x = (float) x;
		this.y = (float) y;
	}
	
	public GLVec2(float x, float y)
	{
		this.x = x;
		this.y = y;
	}
	
	public GLVec2(int x, int y)
	{
		this.x = x;
		this.y = y;
	}
	
	public GLVec2(float[] pos)
	{
		this.x = pos[0];
		this.y = pos[1];
	}
	
	public GLVec2(double[] pos)
	{
		this.x = (float) pos[0];
		this.y = (float) pos[1];
	}
	
	public float x()
	{
		return x;
	}
	
	public float y()
	{
		return y;
	}
	
	public float[] array()
	{
		return new float[]{x,y};
	}
	
	public GLVec2 add(GLVec2 other)
	{
		return new GLVec2(x+other.x, y+other.y);
	}
	
	public GLVec2 add(float x, float y)
	{
		return new GLVec2(this.x+x, this.y+y);
	}
	
	public GLVec2 sub(GLVec2 other)
	{
		return new GLVec2(x-other.x, y-other.y);
	}
	
	public GLVec2 sub(float x, float y)
	{
		return new GLVec2(this.x-x, this.y-y);
	}
	
	
	public GLVec2 mul(double m)
	{
		return new GLVec2(this.x*m, this.y*m);
	}
	
	public GLVec2 mul(double x, double y)
	{
		return new GLVec2(this.x*x, this.y*y);
	}
	
	public GLVec2 mul(GLVec2 other)
	{
		return new GLVec2(this.x*other.x, this.y*other.y);
	}
	
	public GLVec2 neg()
	{
		return new GLVec2(-x,-y);
	}
	
	public float product()
	{
		return x*y;
	}

	public float length()
	{
		return (float) Math.sqrt(x*x + y*y);
	}
	
	public GLVec2 normalize()
	{
		return this.mul(1 / length());
	}
	
	public String toString()
	{
		return "[" + x + "," + y + "]";
	}

}
